from typing import Union, Tuple, List

from pydantic import BaseModel, Field, validator

# todo: 添加嵌套约束对象
class Address(BaseModel):
    street: str
    city: Tuple[str]
    postal_code: Union[str, int]

class Person(BaseModel):
    name: str
    age: int
    email: str
    address: List[Address]

class PersonData(BaseModel):
    name: str
    age: int = Field(default=18)
    email: str

    @validator('email')
    def validate_email(cls, value):
        if not value.endswith('@example.com'):
            raise ValueError("Email must be from example.com domain")
        return value
